package com.badou.project.common.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.badou.brms.cfg.syscache.SystemCacheContainer;
import com.badou.brms.dictionary.DictionaryCacheContainer;
import com.badou.core.factory.InstanceFactory;
import com.badou.logs.syslog.performace.ResourceCacheContainer;
import com.badou.logs.syslog.performace.config.ConfigFactory;
import com.badou.logs.syslog.service.ILogonLogService;
import com.badou.project.common.util.ProjectPropertiesLoader;
import com.badou.tools.common.cache.CacheFactory;
import com.badou.tools.common.cfg.ConfigContainer;
import com.badou.tools.common.properties.CacheProperties;
import com.badou.tools.common.util.SpringHelper;
 
/**
 * @author Lin zhaolinzhi@badousoft.com
 * @version $Revision$ $Date$ ${time}$
 * @modifyed by Lin(mail) description
 * @purpose add this file description here
 */
public class AppStartupLoaderListener implements ServletContextListener{
	public void contextDestroyed(ServletContextEvent arg0) {
 		ConfigContainer.getInstance().destroy();
	}

	public void contextInitialized(ServletContextEvent arg0) {
		SpringHelper.setServletContent(arg0.getServletContext());
		InstanceFactory.setServletContent(arg0.getServletContext());
        
        ConfigContainer.getInstance().register(CacheProperties.class);
        CacheFactory.getInstance().init();
        
        ConfigContainer.getInstance().register(ProjectPropertiesLoader.class);
        
        DictionaryCacheContainer.getInstance().init();
        SystemCacheContainer.getInstance().init();
        
        // 注销未注销的登录日志
		ILogonLogService logonLogService = InstanceFactory.getInstance(ILogonLogService.class);
/*		logonLogService.updateLogoutData(null);        
*/        
        ConfigFactory.configure(this.getClass().getClassLoader().getResource("/").getPath());
        ResourceCacheContainer.getInstance().init();
 	}
}

